package com.gopay.bis.ceb.expay.operation;

import com.csii.payment.client.entity.RequestParameterObject;
import com.csii.payment.client.http.HttpUtil;
import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.common.constants.bank.BankConstants;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.ExPayBaseMessage;
import com.gopay.common.exception.GopayException;

/**
 *
 * @author lilili
 * @CebExPayDataSubmit.java
 *
 */
public class CebExPayDataSubmit {

    private CebHttpsTransport cebHttpsTransport;

    public Object submitData(String data,String url) throws GopayException {
        String res = null;
        try {
            RequestParameterObject requestParam = new RequestParameterObject();
            requestParam.setRequestData(data); // 设置请求数据
            requestParam.setRequestURL(url); // 设置请求地址
            requestParam.setConnectTimeout("40000"); // 设置通讯连接时间，单位毫秒
            requestParam.setRequestCharset("utf-8"); // 默认为gbk
            requestParam.addRequestProperties("Content-Type", "text/xml; charset=utf-8");
            requestParam.setResponseCharset("gbk"); // 设置响应字符集，默认gbk
            requestParam.setVerifyFlag(false); // 设置https验证标志：true-验证
            byte[] resBytes = HttpUtil.sendHost(requestParam);
            res = new String(resBytes, "gbk");

        } catch (Exception e) {
            e.printStackTrace();
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E6057, e.getMessage());
        }

        return res;
    }

    /**
     * 光大提交地址
     */
    private String url="https://www.cebbank.com/agreeEpay/quickPayAccess.do";
    //private String url="https://ebtest.cebbank.com/agreeEpayper/quickPayAccess.do";
    public Object submitData(String data){
        ExPayBaseMessage baseMessage = new ExPayBaseMessage();
        baseMessage.setBank(BankConstants.BANK_LOGO_CEB);
        try {
            byte[] submitData = data.getBytes("UTF-8");
            Object messageData = new Object();
            cebHttpsTransport.setUrl(url);
            messageData = cebHttpsTransport.submit(submitData);
            return messageData;
        } catch (Exception e) {
            BankLogUtils.printExPayExceptionLog(baseMessage, e);
            return null;
        }
        
        
    }
    
    public CebHttpsTransport getCebHttpsTransport() {
        return cebHttpsTransport;
    }

    public void setCebHttpsTransport(CebHttpsTransport cebHttpsTransport) {
        this.cebHttpsTransport = cebHttpsTransport;
    }


}
